<template>
  <!-- 供应商列表 -->
  <div class="app-container">
    <el-form :model="queryParams" :inline="true" label-width="90px">
      <el-form-item label="供应商信息" style="margin-left: -10px">
        <el-input
          v-model="queryParams.supplierName"
          placeholder="供应商名称/负责人/联系方式"
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="供应商负责人" label-width="106px">
        <el-input
          v-model="queryParams.leadingCadre"
          placeholder="请输入供应商负责人"
          size="small"
          style="width: 160px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="负责人联系方式" label-width="116px">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入负责人联系方式"
          size="small"
          style="width: 160px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAddOrder"
        >新增</el-button
      >
      <el-button
        type="danger"
        plain
        icon="el-icon-refresh"
        size="mini"
        @click="handleClearCache"
        >刷新</el-button
      >
    </el-row>
    <el-table v-loading="loading" :data="typeList">
      <el-table-column
        label="序号"
        type="index"
        align="center"
        prop=""
        width="150px"
      />
      <el-table-column
        label="供应商名称"
        align="center"
        :show-overflow-tooltip="true"
        prop="supplierName"
      >
      </el-table-column>
      <el-table-column
        label="供应商负责人"
        align="center"
        :show-overflow-tooltip="true"
        prop="leadingCadre"
      >
      </el-table-column>
      <el-table-column
        label="负责人联系方式"
        align="center"
        :show-overflow-tooltip="true"
        prop="telephone"
      >
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        :show-overflow-tooltip="true"
        prop="createTime"
      >
      </el-table-column>
      <el-table-column
        label="备注"
        align="center"
        :show-overflow-tooltip="true"
        prop="remarks"
      >
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        :show-overflow-tooltip="true"
        prop=""
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleGoEdit(scope.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 新建供应商 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body
      @closed="cancel"
      class="dialog"
    >
      <div class="xian_"></div>
      <el-form
        ref="form"
        :model="ruleForm"
        :rules="rulesForm"
        label-width="120px"
        :hide-required-asterisk="true"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="供应商名称" prop="supplierName" label-width="96px" >
              <el-input
                v-model="ruleForm.supplierName"
                placeholder="请输入供应商名称"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="负责人" prop="leadingCadre" label-width="96px" class="item_label">
              <el-input
                v-model="ruleForm.leadingCadre"
                placeholder="请输入供应商负责人"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="联系电话" prop="telephone" label-width="96px" class="item_label">
              <el-input
                v-model="ruleForm.telephone"
                maxlength="11"
                placeholder="请输入联系方式"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" label-width="96px" class="item_label">
              <el-input
                v-model="ruleForm.remarks"
                type="textarea"
                placeholder="请输入内容"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
                <el-row>
          <el-col :span="24">
            <el-form-item label="创建人" label-width="96px" class="item_label">
                <div>{{operator}}</div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button
          type="primary"
          @click="submitForm('form')"
          v-if="title == '新增供应商'"
          >确 定</el-button
        >
        <el-button
          type="primary"
          @click="submitFormEdit('form')"
          v-if="title == '编辑供应商'"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  goodsSupplierList,
  goodsSupplier,
  goodsSupplierEdit,
} from "@/api/goods/index";
export default {
  data() {
    return {
      // hideRequiredAsterisk : false,
      title : "",
      operator : "",
      ruleForm: {
        supplierName: null,
        leadingCadre: null,
        telephone: null,
        remarks: null,
      },
      // 遮罩层
      loading: true,
      // 选中数组
      total: 0,
      // 订单列表
      typeList: [],
      // 是否显示弹出层
      open: false,
      // 搜索状态字典
      statusOptions: [], //支付类型
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        supplierId: null,
        supplierName: null,
        leadingCadre: null,
        telephone: null,
      },
      rulesForm: {
        supplierName: [
          { message: "请输入供应商名称", trigger: "blur", required: true },
        ],
        leadingCadre: [
          { message: "请输入供应商负责人", trigger: "blur", required: true },
        ],
        telephone: [
          { message: "请输入联系电话", trigger: "blur", required: true },
        ],
      },
    };
  },
  created() {
    this.getList();
      this.operator = localStorage.getItem("userName");
  },
  methods: {
    handleGoEdit(row) {
      this.open = true;
      this.title = "编辑供应商";
      //编辑
      this.ruleForm = {
        supplierName: row.supplierName,
        leadingCadre: row.leadingCadre,
        telephone: row.telephone,
        remarks: row.remarks,
        supplierId: row.supplierId,
      };
    },
    submitFormEdit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          goodsSupplierEdit(this.ruleForm).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: "编辑供应商成功",
                type: "success",
              });
              this.open = false;
              setTimeout(() => {
                this.getList();
                this.ruleForm = {
                  supplierName: null,
                  leadingCadre: null,
                  telephone: null,
                  remarks: null,
                  supplierId: null,
                };
              }, 100);
            }
          });
        } else {
          return false;
        }
      });
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          goodsSupplier(this.ruleForm).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: "新增供应商成功",
                type: "success",
              });
              this.open = false;
              setTimeout(() => {
                this.getList();
                this.ruleForm = {
                  supplierName: null,
                  leadingCadre: null,
                  telephone: null,
                  remarks: null,
                };
              }, 100);
            }
          });
        } else {
          return false;
        }
      });
    },
    cancel() {
      //创建取消
      this.open = false;
      this.ruleForm = {
        supplierName: null,
        leadingCadre: null,
        telephone: null,
        remarks: null,
        supplierId: null,
      };
    },
    handleAddOrder() {
      this.title = "新增供应商";
      this.open = true;
    },
    handleClearCache() {
      window.location.reload();
    },
    /** 查询字典类型列表 */
    getList(index) {
      this.loading = true;
      goodsSupplierList(this.queryParams).then((response) => {
        this.typeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      //重置事件
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        supplierId: null,
        supplierName: null,
        leadingCadre: null,
        telephone: null,
      };
      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped>
.el-input--medium{
  Text-align:"" !important;
  text-align-last: "" !important ;
}
 .dialog  .item_label ::v-deep .el-form-item__label {
  width: 80px !important;
  Text-align:justify !important;
  text-align-last:justify !important;
  width: 80px !important;
  margin-left: 14px ;
}
.xian_ {
  height: 1px;
  width: 500px;
  background-color: #eee;
  margin-left: -20px;
  margin-top: -25px;
  margin-bottom: 30px;
}
.dialog-footer {
  margin-top: -10px;
  display: flex;
  justify-content: center;
}
.el-input--medium {
  margin-bottom: 10px !important;
}
.el-range-editor {
  width: 100% !important;
}
.app-container {
  .el-col-11 {
    width: 100%;
  }
  .el-form-item__content {
    position: relative !important;
    span {
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #333333;
      position: absolute;
      top: 1px;
      right: 12px;
    }
  }
  .mb8 {
    .title {
      font-size: 20px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #333333;
    }
    .create {
      margin-right: 20 px;
      float: right;
    }
  }
}
</style>